var table;
var element;
var layer;
var $;
var form;
layui.use(['table','element','layer','form'],function() {
    table=layui.table;
    element=layui.element;
    layer=layui.layer;
    $=layui.jquery;
    form=layui.form;
    //页面刷新
    $("#btn_1").on('click',function(){
        location.reload(true);
    })
    ForumExam('','','');
    //微圈审核查询
    function ForumExam(actName,userId,accMoney){
        $.ajax({
            url:"/SyteacherSelController/ForumExam",
            type:"post",
            dataType:"json",
            data:{"actName":actName,"userId":userId,"accMoney":accMoney},
            success:function(data){
                TabView(data.data);
            }
        });
    }

    //课程分类下拉菜单
    $.ajax({
        url: "/SyteacherSelController/selActicleCategraySelect",
        type: "post",
        dataType: "json",
        success: function (data) {
            for(var a=0;a<data.data.length;a++){
                $("#userId").append("<option value='"+data.data[a].id+"'>"+data.data[a].name+"</option>");
            }
            form.render();
        }
    });

    function TabView(da){
        table.render({
            elem:"#tab_id",
            data:da,
            limit:5,
            toolbar:'#toolbarDemo',
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[3,6,9],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:'radio',width:60},
                {title:'序号',align: 'center',templet:function(data){
                        return data.LAY_INDEX;
                 }},
                {field:'url',title:'微圈图片',align: 'center',templet:function(data){

                    if(data.url!=null){
                        return "<img src='"+data.url+"'height='100'>";
                    }else{
                        return "<span>无图片</span>";
                    }

                    }},
                {field:'title',title:'文章名称',align: 'center'},
                {field:'actName',title:'所属分类',align: 'center'},
                {field:'click',title:'点击量',align: 'center'},
                {field:'details',title:'状态',align: 'center',templet:function(data){
                        if(data.details==5){
                            return  "未审核"
                        }else if(data.details==3){
                            return  "已审核"
                        }else{
                            return "未提交"
                        }
                    }
                },
                {title:"操作",width:120,align: 'center',templet:function(data){
                        if(data.details==5){
                            return "<a href='#' onclick='javascript:selectCourseTable(\""+data.id+"\")' style='color: #1ABC9C'>查看</a>&nbsp<a href='#' onclick='javascript:editVue(\""+data.id+"\",\""+data.title+"\")' style='color: #1ABC9C'>审核</a>";
                        }else if(data.details==3){
                            return "<a href='#' onclick='javascript:selectCourseTable(\""+data.id+"\")' style='color: #1ABC9C'>查看</a>&nbsp";
                        }else{
                            return "<a href='#' onclick='javascript:selectCourseTable(\""+data.id+"\")' style='color: #1ABC9C'>查看</a>"
                        }

                    }}

            ]]
        });
    }
    //模糊查询
    $("#btn_2").on("click",function(){
        var actName=$("#actId").val();
        var userId=$("#userId").val();
        var accMoney=$("#accId").val();
        ForumExam(actName,userId,accMoney);
    });
});

//审核
function editVue(id,title){
    layer.open({
        type:2,
        title:"审核详情",
        area:['600px','400px'],
        shade:0.4,
        offset:'auto',
        content:"ForumExamine.html",
        success:function(layero,index){
            var obj = layero.find('iframe').contents();
            obj.find('input[name=forumId]').val(title);
            obj.find('input[name=ForumMId]').val(id);
        }
    })
}

//查看
function selectCourseTable(id){
    var index = layer.open({
        type:2,
        title:"课程详情",
        area:['800px','600px'],
        shade:0.4,
        offset:'auto',
        maxmin: true,
        content:"/operation/comment/TeaEssayView.html",
        success:function(layero,index) {
            //查找当前引入的iframe内容
            var obj = layero.find('iframe').contents();
            //根据选择器选择input,并设置值
            obj.find('input[name=courseId]').val(id);
        }
    });
    layer.full(index);
}